package vista;

import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.Timer;

public class TransicionLadronRoba extends VistaPanel3 implements ActionListener {

    /**
	 * 
	 */
	private static final long serialVersionUID = 197311456353246052L;
	private final static int B_WIDTH = 1366;//350;
    //private final static int B_HEIGHT = 760;//350;
    private final int INITIAL_X = 0;//-40;
    private final int INITIAL_Y = 150;//-40;
    private final int DELAY = 0;
    
    private Image star;
    private Timer timer;
    private int x, y;
    public boolean termine = false;
    private VentanaPrincipal vista;

    public TransicionLadronRoba(JFrame vista) {
        
    	this.vista = (VentanaPrincipal) vista;
        loadImage();
        initBoard();
        
    }
    
    private void loadImage() {
        
        ImageIcon ii = new ImageIcon(VistaDarDatosCaso.class.getResource("/vista/imagenes/ladronescapa.png"));
        star = ii.getImage();        
    }
    
    private void initBoard() {
        
        setBackground(Color.BLACK);

        setDoubleBuffered(true);

        x = INITIAL_X;
        y = INITIAL_Y;
        
        timer = new Timer(DELAY, this);
        timer.start();
    }

    @Override
    public void paintComponent(Graphics g) {
    	if (termine == true){
    		g.dispose();
    		removeAll();
    		((CardLayout) vista.panel3.getLayout()).show(vista.panel3, VistaPanel3CardLayout.PANEL_VACIO);
    		
    		return;
    	}
        super.paintComponent(g);

        drawStar(g);
    }
    
    private void drawStar(Graphics g) {
        
        Graphics2D g2d = (Graphics2D) g;
        g2d.drawImage(star, x, y, this);
        Toolkit.getDefaultToolkit().sync();
        g.dispose();
    }

    @Override
    public void actionPerformed(ActionEvent e) {
 
        x += 10;
        //y += 1;

        if (x > B_WIDTH) {
            termine = true;
        }
        
        repaint();  
    }
}